<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>选择模板</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<script type="text/html" id="formDefHiToolbar">
    <div class="layui-btn-container" style="padding:20px 10px;">
        <a class="layui-btn layui-btn-sm" id="queryFormDefHi" lay-event="queryFormDefHi">
            <i class="layui-icon">&#xe615;</i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="del">
            <i class="layui-icon">&#xe640;</i>
            <span>删除</span>
        </a>
    </div>

    <form class="layui-form" action="" lay-filter="formDefHiFilter" style="margin-top:10px">
        <div class="table-top-filter">
            <div class="table-filter-alone">
                <label class="layui-form-label">表单标题</label>
                <input type="text" class="layui-input filter-value" name="Q_subject_SL"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">描述</label>
                <input type="text" class="layui-input filter-value" name="Q_formDesc_SL"/>
            </div>
            <div class="table-filter-alone">
                <label class="layui-form-label">创建人</label>
                <input type="text" class="layui-input filter-value" name="Q_creator_SL"/>
            </div>

            <div class="table-filter-alone">
                <label class="layui-form-label">创建时间</label>
                <input type="text" name="Q_begincreatetime_DL" autocomplete="off" placeholder="开始时间"
                       class="layui-input start_time filter-value">
                <span style="float:left;margin-left:63px">至</span>
                <input type="text" name="Q_endcreatetime_DG" autocomplete="off" placeholder="结束时间"
                       class="layui-input end_time filter-value" style="margin-left:32px">
            </div>

        </div>
    </form>
</script>
<script type="text/html" id="management">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="recovery">恢复</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<div style="height: 510px;overflow:auto;width: 100%; ">
    <table class="layui-hide" id="formDefHi" lay-filter="formDefHi"></table>
</div>
<div class="layui-form-item">
    <div class="layui-input-block" style="margin:0">
        <div class="layui-footer" style="background: #f2f2f2;position: absolute;left: 45%;">
            <button type="button" class="layui-btn layui-btn-sm layui-btn-danger" id="returnCol">关闭</button>
        </div>
    </div>
</div>
<script>

    layui.config({
        base: serverPath.formPath + staticPath.formPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate', 'jquery', 'table', 'layer', 'commons', 'common'], function () {
        var form = layui.form
            , layer = layui.layer, commons = layui.commons, common = layui.common;
        var table = layui.table;
        var $ = layui.$;
        var setter = layui.setter;
        var index = parent.layer.getFrameIndex(window.name);
        $("#returnCol").on('click', function () {
            parent.layer.close(index);
        })

        //头工具栏事件
        table.on('toolbar(formDefHi)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'queryFormDefHi':
                    common.tableConditionRender("formDefHi", "formDefHiFilter", {where: {}}, false);
                    commons.reflashDate({startName: '.start_time', endName: '.end_time'});
                    break;
                case 'del':
                    if (data.length == 0) {
                        layer.confirm('请选择记录！', {
                            btn: ['确定'] //按钮
                        }, function (index) {
                            layer.close(index);
                        }, function () {
                        });
                    } else {
                        layer.confirm('确定要删除选中的数据吗?', function (index) {
                            var ids = [];
                            for (var i = 0; i < data.length; i++) {
                                ids.push(data[i].hisId);
                            }
                            var hisIds = ids.join(',');
                            $.ajax({
                                url: serverPath.formPath + setter.formLinkPath +"formDefHi/del",
                                dataType: 'json',
                                data: {"hisId": hisIds},
                                success: function (data) {
                                    layer.alert(data.msg);
                                    //执行重载
                                    table.reload('formDefHi', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                }
                            })
                        });
                    }
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(formDefHi)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'del':
                    layer.confirm('确定要删除该记录吗?', function (index) {
                        var hisId = obj.data.hisId;
                        $.ajax({
                            url: serverPath.formPath + setter.formLinkPath +"formDefHi/del",
                            dataType: 'json',
                            data: {"hisId": hisId},
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                table.reload('formDefHi', {
                                    page: {
                                        curr: 1
                                    }
                                });
                            }
                        })
                    });
                    break;
                case 'recovery':
                    layer.confirm('确定要恢复该记录吗?', function (index) {
                        var hisId = obj.data.hisId;
                        $.ajax({
                            url: serverPath.formPath + setter.formLinkPath +"formDefHi/recoveryData",
                            dataType: 'json',
                            data: {"hisId": hisId},
                            success: function (data) {
                                layer.alert(data.msg);
                                //执行重载
                                table.reload('formDefHi', {
                                    page: {
                                        curr: 1
                                    }
                                });
                            }
                        })
                    });
                    break;
            }
        });

        var formDefId = '${formDefId}';
        table.render({
            elem: '#formDefHi',
            cellMinWidth: 80,
            title: '历史记录列表',
            defaultToolbar: [],
            url: serverPath.formPath + setter.formLinkPath +'formDefHi/list?formDefId=' + formDefId, //数据接口
            page: true, //开启分页
            method: 'get',
            toolbar: '#formDefHiToolbar',
            autoSort: false,//禁用前端排序
            cols: [
                [{type: 'checkbox'},
                    {field: 'hisId', title: 'hisId', sort: true, hide: true},
                    {field: 'subject', align: 'center', title: '表单标题', sort: true},
                    {field: 'formDesc', align: 'center', title: '描述', sort: true},
                    {field: 'creator', align: 'center', title: '创建人', sort: true},
                    {
                        field: 'createTime', align: 'center', title: '创建时间', templet: function (d) {
                            return timeData(d.createTime);
                        }, sort: true
                    },
                    {align: 'center', title: '管理', toolbar: '#management'}
                ]
            ]
        });

        window.Initialization = function () {
            commons.reflashDate({startName: '.start_time', endName: '.end_time'});
        };

        /*刷新时间控件*/
        commons.reflashDate({startName: '.start_time', endName: '.end_time'});
        common.tableSort("formDefHi", {show: window.Initialization});
    });
</script>
<style>
    .table-top-filter div {
        display: inline-block;
    }

    .table-top-filter div input {
        border-radius: 4px;
        float: left;
        width: 140px;
    }

    .table-top-filter label.layui-form-label {
        width: 104px;
        float: left;
    }

    .table-top-filter .pullsel .xm-input {
        border-radius: 4px;
        width: 246px;
    }

    .layui-table-tool-temp {
        padding-right: 0;
    }
</style>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>